Import the NumPy library under the alias np
.
Create a NumPy array called my_array
that contains the following elements: 1
, 3
, and 5
.
Create a two-dimensional NumPy array with 9 elements. The array should be called my_matrix
and should have 3 columns and three rows. The matrix can contain whatever values you'd like.
Use NumPy's arange
method to generate the following output:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
Use NumPy's arange
method to generate the following output:
array([ 1, 4, 7, 10, 13])
Hint: You will need to use arange
's third argument.
Generate a NumPy array that contains 20 zeros.
Generate a NumPy array that contains 50 ones.
Using NumPy, divide the space between 0 and 100 into 1000 even intervals.
Create a 10x10 identity matrix using NumPy.
Returns a random sample of numbers with 10 values where each value is between 0 and 1.
Returns a random sample of numbers with 10 values where each value is between 0 and 10.
Hint: Use the random.rand
method combined with a multiplication operation.
Generate a random sample of 15 numbers from a normal distribution.
Generate a random sample of 7 integers that range between 5 and 10.
Reshape the following one-dimensional NumPy array into a two-dimensional Numpy array with 3 rows and 3 columns.
arr = np.array([0,1,2,3,4,5,6,7,8])
Print the minimum and maximum values of the following NumPy array.
arr = np.array([0,1,2,3,4,5,6,7,8])
#Print the minimum value here.
#Print the maximum value here.
For the following NumPy array, print the index of the minimum and maximum values.
my_array = np.array([6, 7, 0, 2])
#Print the minimum value's index here.
#Print the maximum value's index here.